package com.rds.system.service.impl;

import com.rds.common.utils.DateUtils;
import com.rds.system.domain.RdaState;
import com.rds.system.mapper.RdaStateMapper;
import com.rds.system.service.IRdaStateService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 策略状态Service业务层处理
 *
 * @author rds
 * @date 2021-05-05
 */
@Service
public class RdaStateServiceImpl implements IRdaStateService
{
    @Autowired
    private RdaStateMapper rdaStateMapper;

    /**
     * 查询策略状态
     *
     * @param id 策略状态ID
     * @return 策略状态
     */
    @Override
    public RdaState selectRdaStateById(Long id)
    {
        return rdaStateMapper.selectRdaStateById(id);
    }

    /**
     * 查询策略状态列表
     *
     * @param rdaState 策略状态
     * @return 策略状态
     */
    @Override
    public List<RdaState> selectRdaStateList(RdaState rdaState)
    {
        return rdaStateMapper.selectRdaStateList(rdaState);
    }

    /**
     * 查询策略状态
     *
     * @param rdaState 策略状态
     * @return 策略状态集合
     */
    public RdaState selectRdaState(RdaState rdaState)
    {
        return rdaStateMapper.selectRdaState(rdaState);
    }

    /**
     * 根据策略和顺序号查询下一策略状态
     *
     * @param policyid 策略id
     * @param stateid 顺序号
     * @return 策略状态集合
     */
    public RdaState selectRdaStateByPidAndSid(@Param("policyid")Integer policyid, @Param("stateid")Integer stateid,@Param("str")String str)
    {
        return rdaStateMapper.selectRdaStateByPidAndSid(policyid,stateid,str);
    }

    /**
     * 根据策略查询第一个状态
     *
     * @param policyid 策略id
     * @return 策略状态集合
     */
    public Integer selectRdaStateByPid(@Param("policyid")Integer policyid){
        return rdaStateMapper.selectRdaStateByPid(policyid);
    };

    /**
     * 新增策略状态
     *
     * @param rdaState 策略状态
     * @return 结果
     */
    @Override
    public int insertRdaState(RdaState rdaState)
    {
        rdaState.setCreateTime(DateUtils.getNowDate());
        return rdaStateMapper.insertRdaState(rdaState);
    }

    /**
     * 修改策略状态
     *
     * @param rdaState 策略状态
     * @return 结果
     */
    @Override
    public int updateRdaState(RdaState rdaState)
    {
        return rdaStateMapper.updateRdaState(rdaState);
    }

    /**
     * 批量删除策略状态
     *
     * @param ids 需要删除的策略状态ID
     * @return 结果
     */
    @Override
    public int deleteRdaStateByIds(Long[] ids)
    {
        return rdaStateMapper.deleteRdaStateByIds(ids);
    }

    /**
     * 删除策略状态信息
     *
     * @param id 策略状态ID
     * @return 结果
     */
    @Override
    public int deleteRdaStateById(Long id)
    {
        return rdaStateMapper.deleteRdaStateById(id);
    }

    /**
     * 根据策略查询管理状态信息
     * @param policyId 策略ID
     * @return 状态集合
     */
    @Override
    public List<RdaState> getStatesByPolicyId(Long policyId) {
        return rdaStateMapper.getStatesByPolicyId(policyId);
    }

    /** 根据策略id和状态名称查询状态id **/
    @Override
    public Long selectRdaStateId(@Param("policyId")Long policyId,@Param("name")String name){
        return rdaStateMapper.selectRdaStateId(policyId,name);
    }
}
